<?php
namespace app\admin\controller;
use think\Controller;
class Base extends Controller{
    protected $userid = 0;
    protected $role = 0;
    public function __construct(){
        parent::__construct();

        $token = request()->header('Authorization');
        if($token){
            $signer = new \Lcobucci\JWT\Signer\Hmac\Sha256();
            $token = (new \Lcobucci\JWT\Parser())->parse($token);
            $res = $token->verify($signer,'@#$%^&*qwe%r&t^yuio===');
            if($res == true){
                $userid = $token->getClaim('key', false);
                $this->role = $token->getClaim('role', false); //
                $this->userid = base64_decode($userid) / 1314;
            }
        }
        
        
        /* $token = session('Authorization');
        if(!$token){
            $token = $request->header('Authorization');
            if(!$token){
                if(input("param.u")){
                    $token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6IjUyMCJ9.eyJpc3MiOiJcdTVjMWFlXHU1MTQ1IiwiYXVkIjoiXHU1YzFhZVx1NTE0NSIsImp0aSI6IjUyMCIsImlhdCI6MTUzNDQ3NjgzMiwia2V5IjoiTVRNeE5BPT0iLCJyb2xlIjowfQ.WnI0-Zc9sxpT6lAXY-eag47vJElvQo9ERudSs-B3cs8";
                }
            }
        }
        
        if($token){
            include ROOT_PATH . "/vendor/autoload.php";
            $signer = new \Lcobucci\JWT\Signer\Hmac\Sha256();
            $token = (new \Lcobucci\JWT\Parser())->parse($token);
            $res = $token->verify($signer,"@#$%^&*qwe%r&t^yuio===");
            if(!$res){
                echo json_encode(["code"=>301,"msg"=>"请登录"]);
                exit;
            }
            $userid = $token->getClaim("key",false);
            $this->role = $token->getClaim("role",false); //0:平台，1：代理商，2：门店
            $this->userid = base64_decode($userid) / 1314;
            
            session("role",$this->role);
        }else{
            echo json_encode(["code"=>301,"msg"=>"请登录"]);
            exit;
        } */
        
        
    }
    
    public function noLogin() {
        return $this->userid == 0;
    }
    
    public function noLoginReturn() {
        return errorResult('未登陆', 301);
    }
}